﻿using System.Windows;
using System.Windows.Input;
using Microsoft.ApplicationServer.Caching.AdminApi;

namespace MDCAdminTool.Commands
{
    public class StartCacheCluster : AsyncCommandBindingBase
    {
        public StartCacheCluster() : base()
        {
            Command = Application.Current.Resources["StartCacheCluster"] as ICommand;
        }

        protected override void OnExecuted( object sender , ExecutedRoutedEventArgs e )
        {
            var service = e.Parameter as ICacheCommand;
            if (service != null)
            {
                service.Start();
            }
        }

        protected override void OnCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            var service = e.Parameter as ICacheCommand;

            if (service != null)
               e.CanExecute = service.Status != ServiceStatus.Up && service.Status != ServiceStatus.Starting;
        }

    }
}